package com.fadadianqi.goods.dao.ibatis;

import com.fadadianqi.commons.GenericDAOSuport;
import com.fadadianqi.goods.dao.BrandDAO;
import com.fadadianqi.goods.model.Brand;
import com.yeqiangwei.commons.util.Pagination;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author aroot
 */
@Component
public class BrandDAOImpl extends GenericDAOSuport<String, Brand> implements
        BrandDAO {

    @Override
    protected Class<?> getObjectClass() {
        return Brand.class;
    }

    @Override
    protected String getTableName() {
        return "brand";
    }

    @Override
    public List<Brand> findAll() {
        Pagination pagination = new Pagination(1, 3000);
        pagination.setOrderList(new Pagination.Order[]{
                Pagination.getNewOrder("first_letter", Boolean.TRUE)
        });
        return super.findAll(pagination);
    }

    @Override
    public Brand getByName(String name) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put(Brand.PROP_NAME, name);
        return super.getByPropertys(map);
    }

    @Override
    public int count() {
        return super.countAll(null);
    }

    @Override
    public int count(String firstLetter) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("firstLetter", firstLetter);
        return super.countAll(map);
    }

    @Override
    public List<Brand> findAll(String firstLetter, Pagination pagination) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("pagination", pagination);
        map.put("firstLetter", firstLetter);
        return super.findByPropertys(map);
    }
}